import Vue from 'vue'
import Router from 'vue-router'
/* 路由外部容器layout */
import Layout from '@/layout'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      // component: () => import('@/views/login/index')
      component: require('@/views/login/index').default
    },
    {
      path: '/home',
      redirect: '/home/index',
      component: Layout,
      children: [
        {
          path: 'index',
          name: 'home',
          component: require('@/views/home/index').default
        }
      ]
    },
    {
      path: '/register',
      name: 'register',
      component: require('@/views/register/index').default,
    },
    {
      path: '/chat',
      name: 'chat',
      redirect: '/chat/index',
      component: require('@/views/chat/index').default,
    },
    {
      path: '/kline',
      redirect: '/kline/index',
      component: Layout,
      children: [
        {
          path: 'index',
          name: 'kline',
          component: () => import('@/views/KLine/index')
        }
      ]
    },
    {
      path: '/mini',
      name: 'mini',
      component: require('@/views/mini/index').default
    },
    {
      path: '*',
      redirect: '/'
    }
  ]
})

router.beforeEach((to, from, next) => {
  // console.log(to)
  // console.log(from)
  if (to.name === 'login' && from.name === 'home') {
    return;
  }
  next()
})

export default router